package com.lsl.bhllserver.service.product;

import java.util.List;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import com.lsl.bhllserver.entity.Product;
import com.lsl.bhllserver.service.func.IAddProd;
import com.lsl.bhllserver.service.func.IDeleteProd;
import com.lsl.bhllserver.service.func.IEditProd;

@Service
public class BusProdService extends ProductService{

    @CacheEvict(value = "myProd", key = "#ap.addProd().getBusId()")
    public boolean addProd(IAddProd ap) {
        return productDAO.insert(ap.addProd());
    }

    @CacheEvict(value = "myProd", key = "#dp.deleteProd().getBusId()")
    public boolean deleteProd(IDeleteProd dp) {
        return productDAO.delete(dp.deleteProd());
    }

    @CacheEvict(value = "myProd", key = "#ep.editProd().getBusId()")
    public boolean editProd(IEditProd ep) {
        Product temp = ep.editProd();
        return productDAO.update(temp.getId(), temp);
    }

    @Cacheable(value = "myProd", key = "#busid")
    public List<Product> getMyProd(Integer busid) {
        return productDAO.findByBusID(busid);
    }
}
